library(gtsummary)
library(fastDummies)
library(janitor)

## ##

rm(list = ls())

## Get data 
## Note that this table requires data that we can only partially make available publicly

sum_dat <- readRDS('data_private/civey_party_replication.rds')  

sum_dat <- fastDummies::dummy_cols(sum_dat, select_columns = c('age', 'educ', 
                                                               'gender', 'treat_categ'),
                                   remove_selected_columns = F) %>%
  clean_names() %>% 
  dplyr::select(one_of('green', 
                              'afd', 
                              'fdp', 
                              'left', 
                              'spd', 
                              'cdu_csu',
                              'age_18_29_jahrige', 'age_30_39_jahrige',
                              'age_40_49_jahrige', 'age_50_64_jahrige',
                              'age_uber_65_jahrige', 'age_na',
                              'educ_abitur_noch_in_schulischer_ausbildung',
                              'educ_hauptschule_kein_abschluss',
                              'educ_mittlere_reife', 
                              'educ_na',
                              'gender_frauen', 
                              'gender_manner',
                              'treat_categ_none',
                              'treat_categ_schwach',
                              'treat_categ_schwer'))


# create summary

stargazer::stargazer(sum_dat,
                     covariate.labels = c('Vote intention: Green Party',
                                          'Vote intention: AfD', 
                                          'Vote intention: FDP', 
                                          'Vote intention: Left Party',
                                          'Vote intention: SPD', 
                                          'Vote intention: CDU-CSU',
                                          'Age: 18 -- 29',
                                          'Age: 30 -- 39',
                                          'Age: 40 -- 49',
                                          'Age: 50 -- 64',
                                          'Age: 65 and above',
                                          'Age: NA',
                                          'Education: A-levels/still in school',
                                          'Education: High school/no degree',
                                          'Education: High school (10yrs)',
                                          'Education: NA',
                                          'Gender: Female',
                                          'Gender: Male',
                                          'Flooding: none (county-level)',
                                          'Flooding: weak (county-level)',
                                          'Flooding: heavy (county-level)'),
                     label = 'tab:civey_sumstats',
                     title = 'Summary statistics, Civey party preference survey',
                     omit.summary.stat = c("p25", "p75"))



